#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: WANDERSON M.PIMENTA
@Software: PyCharm 、Qt Designer and PySide6
@File: tQLeftColumnUI.py
@Time: 2024/05/11 16:35
@Function：ctQLeftColumn：左侧列（设置 & 信息）
"""
from tQQtCore import *
from .tQLeftColumnButton import *
from .tQLeftColumnIcon import *
from UI.elements.columns.tQLeftColumnUI import ctQLeftColumnUI


class ctQLeftColumn(QWidget):
    # 自定义信号
    leftColumnBtnClicked = Signal(object)
    leftColumnBtnReleased = Signal(object)

    # 初始化
    def __init__(self,
                 parent,
                 app_parent,
                 text_title,
                 text_title_size,
                 text_title_color,
                 dark_one,
                 bg_color,
                 btn_color,
                 btn_color_hover,
                 btn_color_pressed,
                 icon_path,
                 icon_color,
                 icon_color_hover,
                 icon_color_pressed,
                 context_color,
                 icon_close_path,
                 radius=8
                 ):
        """
        左侧列（设置 & 信息）
        """
        super().__init__()
        # 基础布局
        self.__m_base_layout = None

        # <editor-fold desc="参数设置">
        # 参数设置
        self._parent = parent
        self._app_parent = app_parent
        self._text_title = text_title
        self._text_title_size = text_title_size
        self._text_title_color = text_title_color
        self._icon_path = icon_path
        self._dark_one = dark_one
        self._bg_color = bg_color
        self._btn_color = btn_color
        self._btn_color_hover = btn_color_hover
        self._btn_color_pressed = btn_color_pressed
        self._icon_color = icon_color
        self._icon_color_hover = icon_color_hover
        self._icon_color_pressed = icon_color_pressed
        self._context_color = context_color
        self._icon_close_path = icon_close_path
        self._radius = radius

        # </editor-fold>

        # 左侧列布局函数
        self.__f_leftColumnLayoutFunc()

        # 左侧的列 来自 UI\elements\columns\leftColumn.ui
        self.menus = ctQLeftColumnUI()
        self.menus.setupUi(self.content_frame)

        # 关闭按键点击&释放信号
        self.btnClose.clicked.connect(self.__f_btnClicked)
        self.btnClose.released.connect(self.__f_btnReleased)

    # <editor-fold desc="用到的私有方法">

    # 左侧列布局函数
    def __f_leftColumnLayoutFunc(self):
        # 基础布局
        self.__m_base_layout = QVBoxLayout(self)
        self.__m_base_layout.setContentsMargins(0, 0, 0, 0)
        self.__m_base_layout.setSpacing(0)

        # 标题框架
        self.title_frame = QFrame()
        self.title_frame.setMaximumHeight(47)
        self.title_frame.setMinimumHeight(47)

        # 标题布局
        self.title_base_layout = QVBoxLayout(self.title_frame)
        self.title_base_layout.setContentsMargins(5, 3, 5, 3)

        # 标题背景框架
        self.title_bg_frame = QFrame()
        self.title_bg_frame.setObjectName("title_bg_frame")
        self.title_bg_frame.setStyleSheet(f'''
        #title_bg_frame {{
            background-color: {self._bg_color};
            border-radius: {self._radius}px;
        }}
        ''')

        # 标题背景布局
        self.title_bg_layout = QHBoxLayout(self.title_bg_frame)
        self.title_bg_layout.setContentsMargins(5, 5, 5, 5)
        self.title_bg_layout.setSpacing(3)

        # 图标
        self.icon_frame = QFrame()
        self.icon_frame.setFixedSize(30, 30)
        self.icon_frame.setStyleSheet("background: none;")
        self.icon_layout = QVBoxLayout(self.icon_frame)
        self.icon_layout.setContentsMargins(0, 0, 0, 0)
        self.icon_layout.setSpacing(5)
        self.icon = ctQLeftColumnIcon(self._icon_path, self._icon_color)
        self.icon_layout.addWidget(self.icon, Qt.AlignCenter, Qt.AlignCenter)

        # 标签
        self.title_label = QLabel(self._text_title)
        self.title_label.setObjectName("title_label")
        self.title_label.setStyleSheet(f'''
        #title_label {{
            font-size: {self._text_title_size}pt;
            color: {self._text_title_color};
            padding-bottom: 2px;
            background: none;
        }}
        ''')

        # <editor-fold desc="关闭按键">
        # 按键框架
        self.btn_frame = QFrame()
        self.btn_frame.setFixedSize(30, 30)
        self.btn_frame.setStyleSheet("background: none;")

        self.btnClose = ctQLeftColumnButton(self._parent,
                                            self._app_parent,
                                            tooltip_text="关闭",
                                            dark_one=self._dark_one,
                                            bg_color=self._btn_color,
                                            bg_color_hover=self._btn_color_hover,
                                            bg_color_pressed=self._btn_color_pressed,
                                            icon_color=self._icon_color,
                                            icon_color_hover=self._icon_color_hover,
                                            icon_color_pressed=self._icon_color_pressed,
                                            icon_color_active=self._icon_color_pressed,
                                            context_color=self._context_color,
                                            text_foreground=self._text_title_color,
                                            icon_path=self._icon_close_path,
                                            radius=6,
                                            )
        self.btnClose.setParent(self.btn_frame)
        self.btnClose.setObjectName("btn_close_left_column")
        # </editor-fold>

        # 标题背景布局添加控件
        self.title_bg_layout.addWidget(self.icon_frame)
        self.title_bg_layout.addWidget(self.title_label)
        self.title_bg_layout.addWidget(self.btn_frame)

        # 标题布局添加标题背景框架
        self.title_base_layout.addWidget(self.title_bg_frame)

        # 下方内容框架
        self.content_frame = QFrame()
        self.content_frame.setStyleSheet("background: none")

        # 基础布局标题框架、下方内容框架
        self.__m_base_layout.addWidget(self.title_frame)
        self.__m_base_layout.addWidget(self.content_frame)

    # 按键点击信号
    def __f_btnClicked(self):
        self.leftColumnBtnClicked.emit(self.btnClose)

    # 按键释放信号
    def __f_btnReleased(self):
        self.leftColumnBtnReleased.emit(self.btnClose)

    # </editor-fold>
